Imports System
Imports System.Collections
Imports System.Text
Imports System.XML
Imports DotNetNuke.Common.Utilities

Namespace DotNetNuke.Modules.ProjectTracker

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    '''		The StatesController class provides business layer methods
    '''		for States objects used by the ProjectTracker module.
    ''' </summary>
    ''' <remarks></remarks>
    ''' <history>
    '''		[MyGeneration]	5/13/2006 3:30:16 PM	Code file automatically generated from DotNetNuke.dnn_PT_States by MyGeneration v1.1.5.1
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class StatesController

        Implements Entities.Modules.IPortable


        Public Sub New()
            ' default object initialisation	
        End Sub

#Region " Public Methods "

        ''' <summary>
        ''' Adds a new States record
        ''' </summary>
        ''' <returns>Identifier for the newly created object</returns>
        Public Function AddStates(ByVal statesInfo As StatesInfo) As Integer
            Return CType(DataProvider.Instance().AddStates(statesInfo.ModuleID, statesInfo.CreatedByUser, statesInfo.CreatedDate, statesInfo.StateName, statesInfo.Description, statesInfo.Status, statesInfo.ProcessOrder, statesInfo.SubscriberRoles, statesInfo.AuthorizedRoles, statesInfo.Notes, statesInfo.EntrySubject, statesInfo.EntryBody, statesInfo.PassSubject, statesInfo.PassBody, statesInfo.FailSubject, statesInfo.FailBody, statesInfo.DownloadRoles, statesInfo.CommentRoles), Integer)
        End Function


        ''' <summary>
        ''' Updates a specified States
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub UpdateStates(ByVal statesInfo As StatesInfo)
            DataProvider.Instance().UpdateStates(statesInfo.ItemID, statesInfo.ModuleID, statesInfo.CreatedByUser, statesInfo.CreatedDate, statesInfo.StateName, statesInfo.Description, statesInfo.Status, statesInfo.ProcessOrder, statesInfo.SubscriberRoles, statesInfo.AuthorizedRoles, statesInfo.Notes, statesInfo.EntrySubject, statesInfo.EntryBody, statesInfo.PassSubject, statesInfo.PassBody, statesInfo.FailSubject, statesInfo.FailBody, statesInfo.DownloadRoles, statesInfo.CommentRoles)
        End Sub


        ''' <summary>
        ''' Deletes a specified States
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub DeleteStates(ByVal itemID As Integer)
            DataProvider.Instance().DeleteStates(itemID)
        End Sub


        ''' <summary>
        ''' Retrieves the details of a specified States
        ''' </summary>
        ''' <returns>StatesInfo object</returns>
        Public Function GetStatesInfo(ByVal itemID As Integer) As StatesInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetStatesInfo(itemID), GetType(StatesInfo)), StatesInfo)
        End Function


        ''' <summary>
        ''' Retrieves the entire list of StatesList
        ''' </summary>
        ''' <returns>ArrayList of StatesInfo objects</returns>
        Public Function GetStatesList(ByVal moduleID As Integer) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetStatesList(moduleID), GetType(StatesInfo))
        End Function


#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ExportModule implements the IPortable ExportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be exported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Function ExportModule(ByVal ModuleID As Integer) As String Implements Entities.Modules.IPortable.ExportModule
            Dim strXML As New StringBuilder

            Dim arrList As ArrayList = Me.GetStatesList(ModuleID)
            If arrList.Count <> 0 Then
                strXML.Append("<stateslist>")
                For Each objItem As StatesInfo In arrList
                    strXML.Append("<states>")
                    strXML.Append("<itemid>XMLEncode(objItem.ItemID.ToString())</itemid>")
                    strXML.Append("<moduleid>XMLEncode(objItem.ModuleID.ToString())</moduleid>")
                    strXML.Append("<createdbyuser>XMLEncode(objItem.CreatedByUser.ToString())</createdbyuser>")
                    strXML.Append("<createddate>XMLEncode(objItem.CreatedDate.ToString())</createddate>")
                    strXML.Append("<statename>XMLEncode(objItem.StateName.ToString())</statename>")
                    strXML.Append("<description>XMLEncode(objItem.Description.ToString())</description>")
                    strXML.Append("<status>XMLEncode(objItem.Status.ToString())</status>")
                    strXML.Append("<processorder>XMLEncode(objItem.ProcessOrder.ToString())</processorder>")
                    strXML.Append("<subscriberroles>XMLEncode(objItem.SubscriberRoles.ToString())</subscriberroles>")
                    strXML.Append("<authorizedroles>XMLEncode(objItem.AuthorizedRoles.ToString())</authorizedroles>")
                    strXML.Append("<notes>XMLEncode(objItem.Notes.ToString())</notes>")
                    strXML.Append("<entrysubject>XMLEncode(objItem.EntrySubject.ToString())</entrysubject>")
                    strXML.Append("<entrybody>XMLEncode(objItem.EntryBody.ToString())</entrybody>")
                    strXML.Append("<passsubject>XMLEncode(objItem.PassSubject.ToString())</passsubject>")
                    strXML.Append("<passbody>XMLEncode(objItem.PassBody.ToString())</passbody>")
                    strXML.Append("<failsubject>XMLEncode(objItem.FailSubject.ToString())</failsubject>")
                    strXML.Append("<failbody>XMLEncode(objItem.FailBody.ToString())</failbody>")
                    strXML.Append("<downloadroles>XMLEncode(objItem.DownloadRoles.ToString())</downloadroles>")
                    strXML.Append("<commentroles>XMLEncode(objItem.CommentRoles.ToString())</commentroles>")
                    strXML.Append("</states>")
                Next
                strXML.Append("</stateslist>")
            End If

            Return strXML.ToString()

        End Function

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ImportModule implements the IPortable ImportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be imported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserId As Integer) Implements Entities.Modules.IPortable.ImportModule
            Dim xmlList As XmlNode = GetContent(Content, "stateslist")
            For Each xmlItem As XmlNode In xmlList.SelectNodes("states")
                Dim objItem As New StatesInfo
                objItem.ItemID = CType(Null.GetNull(xmlItem.Item("itemid").InnerText, Null.NullInteger), Integer)
                objItem.ModuleID = CType(Null.GetNull(xmlItem.Item("moduleid").InnerText, Null.NullInteger), Integer)
                objItem.CreatedByUser = CType(Null.GetNull(xmlItem.Item("createdbyuser").InnerText, Null.NullInteger), Integer)
                objItem.CreatedDate = CType(Null.GetNull(xmlItem.Item("createddate").InnerText, Null.NullDate), DateTime)
                objItem.StateName = CType(Null.GetNull(xmlItem.Item("statename").InnerText, Null.NullString), String)
                objItem.Description = CType(Null.GetNull(xmlItem.Item("description").InnerText, Null.NullString), String)
                objItem.Status = CType(Null.GetNull(xmlItem.Item("status").InnerText, Null.NullInteger), Integer)
                objItem.ProcessOrder = CType(Null.GetNull(xmlItem.Item("processorder").InnerText, Null.NullInteger), Integer)
                objItem.SubscriberRoles = CType(Null.GetNull(xmlItem.Item("subscriberroles").InnerText, Null.NullString), String)
                objItem.AuthorizedRoles = CType(Null.GetNull(xmlItem.Item("authorizedroles").InnerText, Null.NullString), String)
                objItem.Notes = CType(Null.GetNull(xmlItem.Item("notes").InnerText, Null.NullString), String)
                objItem.EntrySubject = CType(Null.GetNull(xmlItem.Item("entrysubject").InnerText, Null.NullString), String)
                objItem.EntryBody = CType(Null.GetNull(xmlItem.Item("entrybody").InnerText, Null.NullString), String)
                objItem.PassSubject = CType(Null.GetNull(xmlItem.Item("passsubject").InnerText, Null.NullString), String)
                objItem.PassBody = CType(Null.GetNull(xmlItem.Item("passbody").InnerText, Null.NullString), String)
                objItem.FailSubject = CType(Null.GetNull(xmlItem.Item("failsubject").InnerText, Null.NullString), String)
                objItem.FailBody = CType(Null.GetNull(xmlItem.Item("failbody").InnerText, Null.NullString), String)
                objItem.DownloadRoles = CType(Null.GetNull(xmlItem.Item("downloadroles").InnerText, Null.NullString), String)
                objItem.CommentRoles = CType(Null.GetNull(xmlItem.Item("commentroles").InnerText, Null.NullString), String)

                If objItem.ItemID = Null.NullInteger Then
                    Me.AddStates(objItem)
                Else
                    Me.UpdateStates(objItem)
                End If
            Next
        End Sub

#End Region


    End Class

End Namespace
